﻿using System;
using Golem.Indexer;
using Golem.SearchDatabase;

namespace Golem.ZCU_Indexer
{
    class Program
    {
        static DateTime start = DateTime.Now;
        static void Main(string[] args)
        {
            IndexingService index = new IndexingService();
            index.IndexingStarted += new IndexingService.IndexingServiveHandler(index_IndexingStarted);
            index.IndexingEnded += new IndexingService.IndexingServiveHandler(index_IndexingEnded);
            //index.Database = new MongoDatabase("127.0.0.1", "webSearch", String.Empty, String.Empty, autocreate: true); 
            index.Database = new MSSQLDatabase("localhost", "webSearch", "search", "search");
            //index.Database.InitDatabase();

            //return;

            Console.WriteLine("Generuji adresy siti");
            /*for (int i = 0; i < 255; i += 5)
            {
                index.Search.AddNetwork(String.Format("10.10.{0}.0", i), "255.255.255.0");
                index.Search.AddNetwork(String.Format("10.20.{0}.0", i), "255.255.255.0");
                index.Search.AddNetwork(String.Format("10.30.{0}.0", i), "255.255.255.0");
            }*/

            //index.Search.AddNetwork(String.Format("10.10.40.41"), "255.255.255.255");

            index.Search.AddNetwork("10.10.75.21", "255.255.255.255");

            /*
            index.Search.AddNetwork("10.10.1.0", "255.255.255.0");  //Machova 20
            index.Search.AddNetwork("10.10.2.0", "255.255.255.0");  //Machova 20
            index.Search.AddNetwork("10.10.3.0", "255.255.255.0");  //Machova 20

            index.Search.AddNetwork("10.10.10.0", "255.255.255.0");  //Machova 14
            index.Search.AddNetwork("10.10.20.0", "255.255.255.0");  //Machova 14
            index.Search.AddNetwork("10.10.30.0", "255.255.255.0");  //Machova 14

            index.Search.AddNetwork("10.10.40.0", "255.255.255.0");  //Machova 16
            index.Search.AddNetwork("10.10.50.0", "255.255.255.0");  //Machova 16
            index.Search.AddNetwork("10.10.60.0", "255.255.255.0");  //Machova 16
            
            index.Search.AddNetwork("10.10.70.0", "255.255.255.0");  //Machova 20
            index.Search.AddNetwork("10.10.75.0", "255.255.255.0");  //Machova 20
            index.Search.AddNetwork("10.10.80.0", "255.255.255.0");  //Machova 20
            index.Search.AddNetwork("10.10.85.0", "255.255.255.0");  //Machova 20
            index.Search.AddNetwork("10.10.90.0", "255.255.255.0");  //Machova 20
            index.Search.AddNetwork("10.10.95.0", "255.255.255.0");  //Machova 20

            index.Search.AddNetwork("10.10.100.0", "255.255.255.0");  //Baarova 36
            index.Search.AddNetwork("10.10.105.0", "255.255.255.0");  //Baarova 36
            index.Search.AddNetwork("10.10.110.0", "255.255.255.0");  //Baarova 36
            index.Search.AddNetwork("10.10.115.0", "255.255.255.0");  //Baarova 36

            index.Search.AddNetwork("10.10.160.0", "255.255.255.0");  //Klatovska K1
            index.Search.AddNetwork("10.10.170.0", "255.255.255.0");  //Klatovska K1

            index.Search.AddNetwork("10.20.1.0", "255.255.255.0");  //Borska A1
            index.Search.AddNetwork("10.20.2.0", "255.255.255.0");  //Borska A1
            index.Search.AddNetwork("10.20.10.0", "255.255.255.0");  //Borska A1
            index.Search.AddNetwork("10.20.20.0", "255.255.255.0");  //Borska A1
            
            index.Search.AddNetwork("10.20.40.0", "255.255.255.0");  //Borska A2
            index.Search.AddNetwork("10.20.50.0", "255.255.255.0");  //Borska A2
            
            index.Search.AddNetwork("10.20.70.0", "255.255.255.0");  //Borska A3
            index.Search.AddNetwork("10.20.80.0", "255.255.255.0");  //Borska A3
            
            index.Search.AddNetwork("10.20.100.0", "255.255.255.0");  //Borska A4

            index.Search.AddNetwork("10.30.1.0", "255.255.255.0");  //Lochotin L2
            index.Search.AddNetwork("10.30.3.0", "255.255.255.0");  //Lochotin L2
            index.Search.AddNetwork("10.30.40.0", "255.255.255.0");  //Lochotin L2
            index.Search.AddNetwork("10.30.50.0", "255.255.255.0");  //Lochotin L2
            index.Search.AddNetwork("10.30.60.0", "255.255.255.0");  //Lochotin L2

            index.Search.AddNetwork("10.30.10.0", "255.255.255.0");  //Lochotin L1
            index.Search.AddNetwork("10.30.20.0", "255.255.255.0");  //Lochotin L1
            index.Search.AddNetwork("10.30.30.0", "255.255.255.0");  //Lochotin L1

            index.Search.AddNetwork("10.60.1.0", "255.255.255.0");  //Zizkova
            index.Search.AddNetwork("10.60.100.0", "255.255.255.0");  //Zizkova

            index.Search.AddNetwork("10.80.1.0", "255.255.255.0");  //Tylova
            index.Search.AddNetwork("10.80.2.0", "255.255.255.0");  //Tylova
            index.Search.AddNetwork("10.80.3.0", "255.255.255.0");  //Tylova
            index.Search.AddNetwork("10.80.253.0", "255.255.255.0");  //Tylova
            index.Search.AddNetwork("10.80.254.0", "255.255.255.0");  //Tylova
            */
            index.Start();
            index.WaitUntilExit();
            index.Stop();
        }

        static void index_IndexingEnded()
        {
            var end = DateTime.Now;
            Console.WriteLine("Končím indexování v: {0}", end.ToShortTimeString());
            Console.WriteLine("{0} minutes", (end - start).TotalMinutes);
        }

        static void index_IndexingStarted()
        {
            Console.WriteLine("Zahajuji indexování v: {0}", start.ToShortTimeString());
            start = DateTime.Now;
        }
    }
}
